package jsyf.oa.web.device;

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import jsyf.com.util.BaseUtils;
import jsyf.com.util.FastJsonConvert;
import jsyf.com.util.ResponseUtils;
import jsyf.oa.facade.device.DeviceModelFacade;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Created by jjx on 2018/3/8.
 */
@Api(value = "查询品牌设备型号接口", description = "查询品牌设备接口")
@Controller
@RequestMapping("/deviceModel")
public class DeviceModelController {

    @Resource
    private DeviceModelFacade deviceModelFacade;

    @ResponseBody
    @RequestMapping(value = "/getModelList.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "查询品牌型号",
            notes = "查询品牌型号 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "", dataType = "String", paramType = "body")
    public void getModelList(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        /**
         * 自己修改吧！！！！
         * **/
        /*List<JSONObject> records = this.deviceModelFacade.getModelList(jsonData);
        if (null != records) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessArrRespond(records));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("查找失败"));
        }*/
    }

    @ResponseBody
    @RequestMapping(value = "/getModelByModelName.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "查询型号信息通过型号名",
            notes = "查询型号信息通过型号名 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{modelName:''}", dataType = "String", paramType = "body")

    public void getModelByModelName(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonParams = FastJsonConvert.convertJSONToObject(jsonData, JSONObject.class);
        List<JSONObject> records = this.deviceModelFacade.getModelByModelName(jsonData);
        if (null != records) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessArrRespond(records));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("查找失败"));
        }
    }


    @ResponseBody
    @RequestMapping(value = "/getBucketCapacityList.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "查询品牌型号斗容",
            notes = "查询品牌型号斗容 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{brandId:'品牌ID',modelId:'型号名'}", dataType = "String", paramType = "body")

    public void getBucketCapacityList(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonParams = FastJsonConvert.convertJSONToObject(jsonData, JSONObject.class);
        List<JSONObject> records = this.deviceModelFacade.getBucketCapacityList(jsonData);
        if (null != records) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessArrRespond(records));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("查找失败"));
        }
    }

    @ResponseBody
    @RequestMapping(value = "/getLow.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "查询最低报价",
            notes = "查询最低报价 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{bucketCapacity:'斗容',modelId:'型号名'}", dataType = "String", paramType = "body")

    public void getLow(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonParams = FastJsonConvert.convertJSONToObject(jsonData, JSONObject.class);
        /**
         * 自己修改吧！！！！
         * **/
      /*  JSONObject records = this.deviceModelFacade.getLow(jsonData);
        if (null != records) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjHourRespond(records));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("查找失败"));
        }*/
    }

    @ResponseBody
    @RequestMapping(value = "/getById.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "通过id查询型号",
            notes = "通过id查询型号 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "", dataType = "String", paramType = "body")
    public void getById(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject JSONObj = this.deviceModelFacade.getById(jsonData);
        if (null != JSONObj) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjHourRespond(JSONObj));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("查找失败"));
        }
    }

    @ResponseBody
    @RequestMapping(value = "/add.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "添加型号",
            notes = "添加型号 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "", dataType = "String", paramType = "body")
    public void add(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        /**
         * 自己修改吧！！！！
         * **/
        String records = this.deviceModelFacade.add(jsonData);
        JSONObject obj = new JSONObject();
        obj.put("isOk", records);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(obj));
    }

    @ResponseBody
    @RequestMapping(value = "/removeById.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "通过id物理删除型号",
            notes = "通过id物理删除型号 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "", dataType = "String", paramType = "body")
    public void removeById(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        Boolean records = this.deviceModelFacade.removeById(jsonData);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(records.toString()));
    }

    @ResponseBody
    @RequestMapping(value = "/delById.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "通过id逻辑删除型号",
            notes = "通过id逻辑删除型号 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "", dataType = "String", paramType = "body")
    public void delById(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        Boolean records = this.deviceModelFacade.delById(jsonData);
        JSONObject obj = new JSONObject();
        obj.put("isOk", records);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(obj));

    }

    @ResponseBody
    @RequestMapping(value = "/update.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "修改型号信息",
            notes = "修改型号信息 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "", dataType = "String", paramType = "body")
    public void update(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        Boolean records = this.deviceModelFacade.update(jsonData);
        JSONObject obj = new JSONObject();
        obj.put("isOk", records);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(obj));
    }

    @ResponseBody
    @RequestMapping(value = "/getAllModel.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "查询品牌设备型号",
            notes = "查询品牌设备型号 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{'brandName':'','modelName':'','brandId':''}", dataType = "String", paramType = "body")
    public void getAllModel(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject records = this.deviceModelFacade.getAllModel(jsonData);

        if (null != records) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjHourRespond(records));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("查找失败"));
        }
    }

    @ResponseBody
    @RequestMapping(value = "/getBrandListByTypeId.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "查询品牌列表根据类型",
            notes = "查询品牌列表根据类型 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{deviceTypeId:'1',companyId:'2017121617484353B8D81EEAFB4598A6'}", dataType = "String", paramType = "body")
    public void getBrandListByTypeId(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonParams = FastJsonConvert.convertJSONToObject(jsonData, JSONObject.class);
        JSONObject records = this.deviceModelFacade.getBrandListByTypeId(jsonData);
        if (null != records) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(records));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("查找失败"));
        }
    }

    @ResponseBody
    @RequestMapping(value = "/getBrand", method = RequestMethod.POST)
    @ApiOperation(
            value = "查询品牌列表",
            notes = "查询品牌列表",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{deviceTypeId:''}", dataType = "String", paramType = "body")
    public void getBrand(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonParams = FastJsonConvert.convertJSONToObject(jsonData, JSONObject.class);
        JSONObject records = this.deviceModelFacade.getBrand(jsonData);
        if (null != records) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(records));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("查找失败"));
        }
    }

    @ResponseBody
    @RequestMapping(value = "/getModelListByBrandId.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "查询型号列表根据品牌",
            notes = "查询型号列表根据品牌 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{brandId:'2018030812524F958DA4817F9A4A40A6',deviceTypeId:''}", dataType = "String", paramType = "body")
    public void getModelListByBrandId(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonParams = FastJsonConvert.convertJSONToObject(jsonData, JSONObject.class);
        JSONObject records = this.deviceModelFacade.getModelListByBrandId(jsonData);
        if (null != records) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(records));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("查找失败"));
        }
    }

    @ResponseBody
    @RequestMapping(value = "/getModelListByBId.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "查询型号列表根据品牌",
            notes = "查询型号列表根据品牌 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{brandId:'2018030812524F958DA4817F9A4A40A6',deviceTypeId:''}", dataType = "String", paramType = "body")
    public void getModelListByBId(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonParams = FastJsonConvert.convertJSONToObject(jsonData, JSONObject.class);
        JSONObject records = this.deviceModelFacade.getModelListByBId(jsonData);
        if (null != records) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(records));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("查找失败"));
        }
    }

    @ResponseBody
    @RequestMapping(value = "/getBrandByCompanyId.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "查询型号列表根据公司",
            notes = "查询型号列表根据公司 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{companyId:''}", dataType = "String", paramType = "body")
    public void getBrandByCompanyId(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject records = this.deviceModelFacade.getBrandByCompanyId(jsonData);
        if (null != records) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(records));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("查找失败"));
        }
    }
}
